﻿using CNotebook.Sales;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class FND_PRICELISTCODE : RibbonForm
    {
        public FND_PRICELISTCODE()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string SelectedPriceListCode { get; set; }
        public string SelectedPriceListName { get; set; }

        private void FND_PRICELISTCODE_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 0;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            PriceManager oManager = new PriceManager();

            string sSearch = string.Format("%{0}%" ,txtSearch.Text.Trim());
            DataTable _TABLE = new DataTable();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            switch (cboSearch.SelectedIndex)
            {
                case 0:
                    _TABLE = oManager.BrowsePriceListByCode(sSearch);
                    break;
                case 1:
                    _TABLE = oManager.BrowsePriceListByCode(sSearch);
                    break;
            }
            oManager.Close();
            gridControl1.DataSource = _TABLE;
            gridControl1.Refresh();

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int[] iRow = gridView1.GetSelectedRows();

            int iRowNum = iRow[0];

            this.SelectedPriceListCode = gridView1.GetRowCellValue(iRowNum, gridView1.Columns["PRICELISTCODE"]).ToString();
            this.SelectedPriceListName = gridView1.GetRowCellValue(iRowNum, gridView1.Columns["PRICELISTNAME"]).ToString();

            this.Close();
        }
    }
}
